package com.infore.airsupervise.biz.impl;

import com.infore.airsupervise.app.Constants;
import com.infore.airsupervise.app.MsgConst;
import com.infore.airsupervise.bean.StationAlarmE;
import com.infore.airsupervise.biz.StationAlarmBiz;
import com.infore.airsupervise.http.BaseResponse;
import com.infore.airsupervise.http.HttpAPI;
import com.infore.airsupervise.http.HttpCallBack;
import com.infore.airsupervise.http.HttpUtil;
import com.infore.airsupervise.http.OnServerResponseListener;
import com.infore.airsupervise.utils.JSONUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;

/**
 * @features: 地图报警 业务实现类
 * @author: WuTao
 * @date: 2017/3/15 10:44
 */
public class StationAlarmBizImpl implements StationAlarmBiz {
    @Override
    public Call sendRealAlarmRequest(String userId, int type, int level, int pageNum, final OnServerResponseListener<List<StationAlarmE>> listener) {
        Map<String,Object> params= new HashMap<>();
        params.put(Constants.USER_ID_KEY,userId);
        params.put("warningLevel",level);
        params.put(Constants.PAGER_NUM_KEY,pageNum);
        params.put("type",type);
        Call<BaseResponse> call=HttpUtil.getHttpService().postParams(HttpAPI.GET_ALARM_LIST,params);
        call.enqueue( new HttpCallBack(){
            @Override
            public void onSuccess(int operationCode, BaseResponse response) {
                super.onSuccess(operationCode, response);
                List<StationAlarmE> alarmEList = JSONUtil.parseList(response.getData(),Constants.RESPONSE_BEAN_LIST_KEY,StationAlarmE.class);
                    listener.onSucceed(alarmEList,operationCode+"");
            }

            @Override
            public void onException(int errorCode, String title, String desc) {
                super.onException(errorCode, title, desc);
                listener.onFailed(errorCode, title, desc);
            }

            @Override
            public void onFailed(int operationCode, String desc) {
                super.onFailed(operationCode, desc);
                listener.onFailed(operationCode, MsgConst.GET_DATA_FAILED, desc);
            }
        });
        return call;
    }
}
